<template>
  <div class="setting">
    <el-icon @click="drawer = true">
      <Setting style="width:30px; height:30px" />
    </el-icon>
    <el-drawer v-model="drawer" title="" :with-header="false" size="300px">
      <div class="drawer">
        <div class="drawer-top">
          <span>项目配置</span>
          <el-icon @click="drawer = false">
            <Close />
          </el-icon>
        </div>
        <div class="drawer-nav">
          <el-divider> <span class="title">主题</span> </el-divider>
          <switchTopic />
        </div>
        <div class="drawer-nav">
          <el-divider> <span class="title">导航栏模式</span> </el-divider>
          <div class="imgs cp">
            <img :class="{'active':store.navMode==='left'}" @click="imgClick('left')" src="@/assets/img/layout/left.png" alt="">
            <img :class="{'active':store.navMode==='center'}" @click="imgClick('center')" src="@/assets/img/layout/center.png" alt="">
          </div>
        </div>
        <div class="drawer-nav">
          <el-divider> <span class="title">主题色</span> </el-divider>
          <ul class="cp">
            <li v-for="val,key in colorStore.colorList" :style="{ background: val.themeColor }" :key="val.themeColor"
              @click="colorStore.changeDefaultTheme(key)">
              <el-icon v-show="key===colorStore.defaultTheme" :style="{color:key==='light'?'#000':'#FFFFFF'}">
                <Check />
              </el-icon>
            </li>
          </ul>
        </div>
        <el-button type="danger" @click="clear"> 清空缓存并返回登录页 </el-button>
      </div>

    </el-drawer>

  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";

import { useColorThemeStore } from "@/stores/colotTheme";
import { useIndexStore } from "@/stores/index";
import { removeUserToken } from "@/utils/user";

const drawer = ref<boolean>(false);
const store = useIndexStore();
const router = useRouter();
const colorStore = useColorThemeStore()
const imgClick = (val: string) => {
  store.updateNavMode(val);
};
const clear =()=>{
  localStorage.removeItem('lang')
  localStorage.removeItem('Index')
  localStorage.removeItem('tabBar')
  localStorage.removeItem('defaultTheme')
  localStorage.removeItem('useDarkKEY')
  localStorage.removeItem('vueuse-color-scheme')
  colorStore.changeDefaultTheme("default");
  router.push('/login')
  removeUserToken();
}
</script>

<style scoped lang="scss">
.setting {
  margin-left: 10px;
  line-height: 0px;
  font-size: 18px;
}
.drawer {
  padding: 0 10px;
  .drawer-top {
    height: 60px;
    line-height: 60px;
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .title {
      font-weight: 600;
      font-size: 18px;
    }
  }
  .drawer-nav {
    min-height: 80px;
    line-height: 60px;
    text-align: center;
    li {
      display: inline-block;
      width: 20px;
      height: 20px;
      border-radius: 2px;
      margin-right: 5px;
      position: relative;

      &:nth-child(2) {
        border: 1px solid #ccc;
      }
      .el-icon {
        position: absolute;
        left: 0px;
        top: 2px;
      }
    }
    .imgs {
      display: flex;
      justify-content: space-around;
      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
        border-radius: 4px;
        &.active {
          border: 2px solid $themeColor;
        }
      }
    }
    .interface {
    }
  }
}

::v-deep .el-drawer__body {
  padding: 0;
}
</style>